package com.hzy.ums.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.hzy.ums.domain.bo.MemberAddressBo;
import com.hzy.ums.domain.vo.MemberAddressVo;
import com.hzy.ums.service.IMemberAddressService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 会员收货地址
 *
 * @author zengxin
 * @date 2023-10-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ums/memberAddress")
public class MemberAddressController extends BaseController {

    private final IMemberAddressService iMemberAddressService;

    /**
     * 查询会员收货地址列表
     */
    @GetMapping("/list")
    public TableDataInfo<MemberAddressVo> list(MemberAddressBo bo, PageQuery pageQuery) {
        return iMemberAddressService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取会员收货地址详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<MemberAddressVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iMemberAddressService.queryById(id));
    }

    /**
     * 新增会员收货地址
     */
    @Log(title = "会员收货地址", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MemberAddressBo bo) {
        return toAjax(iMemberAddressService.insertByBo(bo));
    }

    /**
     * 修改会员收货地址
     */
    @Log(title = "会员收货地址", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MemberAddressBo bo) {
        return toAjax(iMemberAddressService.updateByBo(bo));
    }

    /**
     * 删除会员收货地址
     *
     * @param ids 主键串
     */
    @Log(title = "会员收货地址", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iMemberAddressService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
